package com.financing.service.user;
import java.util.Arrays;
import java.util.Map;

import com.financing.model.user.User;
import com.financing.model.user.UserReferee;
import com.financing.service.BaseService;
import com.financing.util.Money;
import com.jfinal.plugin.activerecord.Page;

public class UserRefereeService extends BaseService<User>{

	/**
	 * 根据类型获取数据
	 * @return 
	 */
	public UserReferee findByUser(int userId) {
		return UserReferee.me.findFirst("select * from user_referee where user_id=?", userId);
	}
	
	/**
	 * 根据类型获取数据
	 * @return 
	 */
	public double totalRefereeShare(int userId) {
		UserReferee ur = UserReferee.me.findFirst("select sum(amount) as total from user_referee where referee_id=?", userId);
		return Money.get(ur.getDouble("total"));
	}

	/**
	 * 分页信息
	 * @param map 
	 * @return 
	 */
	public Page<UserReferee> list(int page, int size, Map<String, String> map) {
		return UserReferee.me.paginate(page,size,buildSql("user_referee",Arrays.asList("referee_id","referee_mobile","mobile","create_time"),map));
	}
}
